package cn.wgx.module.ent.mapper;

import cn.wgx.common.base.IBaseMapper;
import cn.wgx.common.entity.ent.EntUserApp;
import cn.wgx.common.entity.sys.SysApp;
import cn.wgx.common.entity.sys.SysUser;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface EntUserAppMapper extends IBaseMapper<EntUserApp> {

    @Select("select sa.app_id,sa.name,sa.des,sa.remark " +
            "from sys_app sa " +
            "where app_id not in (select app_id from ent_user_app where ent_user_id = #{ent_user_id} and ent_id = #{end_id}) " +
            "and app_id in ( select app_id from ent_app where ent_id = #{end_id})")
    Page<SysApp> listAppNotInEntUser(Page<SysApp> page,
                                     @Param("ent_user_id") Integer ent_user_id,
                                     @Param("end_id") Integer ent_id);

    @Select("SELECT su.user_id,su.username,su.nickname,su.sex,su.photo " +
            "FROM sys_user su " +
            "WHERE user_id IN " +
            "(SELECT user_id FROM ent_user " +
            "WHERE ent_id = #{ent_id} and user_id NOT IN" +
            "(SELECT ent_user_id FROM ent_user_app WHERE ent_id = #{ent_id} and app_id =#{app_id}))" +
            "and nickname like #{nickname}")
    Page<SysUser> listUserNotInEntApp(Page<SysUser> page, Integer app_id, Integer ent_id, String nickname);
}
